package com.xjrsoft.config;

import com.xxl.job.core.executor.XxlJobExecutor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/**
 * @author Zexy
 */
//@Configuration
//@ConditionalOnProperty(prefix = "xjrsoft.job.enabled", name = "xxl-job", havingValue = "true")
@Slf4j
public class XxlJobConfig {
 
    @Value("${xjrsoft.job.admin.addresses}")
    private String adminAddresses;
 
    @Value("${xjrsoft.job.executor.appname}")
    private String appName;
 
    @Value("${xjrsoft.job.executor.ip}")
    private String ip;
 
    @Value("${xjrsoft.job.executor.port}")
    private int port;
 
    @Value("${xjrsoft.job.accessToken}")
    private String accessToken;
 
    @Value("${xjrsoft.job.executor.logpath}")
    private String logPath;
 
    @Value("${xjrsoft.job.executor.logretentiondays}")
    private int logRetentionDays;
 
 
    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobExecutor xxlJobExecutor() {
        log.info("------------xxl-job config init---------------");
        XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
        xxlJobExecutor.setAdminAddresses(adminAddresses);
        xxlJobExecutor.setAppname(appName);
        xxlJobExecutor.setIp(ip);
        xxlJobExecutor.setPort(port);
        xxlJobExecutor.setAccessToken(accessToken);
        xxlJobExecutor.setLogPath(logPath);
        xxlJobExecutor.setLogRetentionDays(logRetentionDays);
        return xxlJobExecutor;
    }
}